﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Convertor
{
    /// <summary>
    /// ConfigWindow.xaml 的交互逻辑
    /// </summary>
    public partial class ConfigWindow : Window
    {
        public ConfigWindow()
        {
            InitializeComponent();
        }

        private bool close;
        private void Window_KeyDown(object sender, KeyEventArgs e)
        {
            if (Config.GlobalConfig.EnableEscToCloseChildWindows && this.IsActive && e.Key == Key.Escape)
            {
                close = true;
            }
        }
        
        private void Window_KeyUp(object sender, KeyEventArgs e)
        {
            if (close && Config.GlobalConfig.EnableEscToCloseChildWindows && this.IsActive && e.Key == Key.Escape)
            {
                this.Close();
            }
        }

        private void Button_Reset_Click(object sender, RoutedEventArgs e)
        {
            Config.GlobalConfig.Reset();
        }

        private void Button_WorkPath_Click(object sender, RoutedEventArgs e)
        {
            using (var dlg = new System.Windows.Forms.FolderBrowserDialog())
            {
                dlg.SelectedPath = Config.GlobalConfig.WorkspacePath;
                dlg.ShowNewFolderButton = true;
                var result = dlg.ShowDialog();
                if (result == System.Windows.Forms.DialogResult.OK)
                {
                    Config.GlobalConfig.WorkspacePath = dlg.SelectedPath;
                }
            }
        }

    }
}
